home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 981 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: news.sprintlink.net!datalytics!news
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: void pointers
  5. Date: 8 Jan 1996 19:23:32 GMT
  6. Organization: Datalytics, Inc
  7. Message-ID: <4crqvk$h4r@gold.datalytics.com>
  8. References: <Pine.SUN.3.91.960105113409.18158A-100000@phoenix.acms.arizona.edu>
  9. NNTP-Posting-Host: pc071.datalytics.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. Kenton White <jwhite@phoenix.acms.arizona.edu> wrote:
  16. >
  17. >
  18. >I am trying to create a class that stores pointers to other classes in an
  19. >array of void pointers.  Since void pointers cannot be dereferenced, is
  20. >there any way to cast the void pointer to a non-void pointer and then
  21. >dereference? 
  22. >
  23.  
  24. Sure.  Cast it and dereference it.
  25.  
  26. Seriously, this raises the spectre of knowing the actual type 
  27. of what you're pointing to so you cast it to a valid type.  
  28. You cannot cast a pointer to an arbitrary type.  Since you're 
  29. talking about classes, the pointer can only be cast to the 
  30. actual type or a base class of the actual type.  If you're 
  31. taking the pointer as a void*, how will you know what to cast 
  32. it to later?
  33.  
  34. -- 
  35. Robert Stewart        | My opinions are usually my own.
  36. Datalytics, Inc.
  37. (513)226-7700
  38. stew@datalytics.com
  39.  
  40.  
  41.